﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Utilities;
using System.IO;
using System.Data;

namespace StockCommon.data.TradeDetail
{
    public class StockMinuteTradeDataProvider
    {
        public class StockDailyDetailSummary
        {
            public String 代號 { get; set; }
            public String 名稱 { get; set; }
            public String 市場 { get; set; }
            public String 產業 { get; set; }
            public DateTime 日期 { get; set; }
            public List<StockMinuteDataSlice> slices { get; set; }
            public double 前收價 { get; set; }
            public double 漲停價 { get; set; }
            public double 跌停價 { get; set; }
            public int 成交量 { get; set; }
            public int 成交值 { get; set; }
        }


        protected static String getDataFileName(String code,DateTime date)
        {
            String fileName=String.Format(@"D:\stockdata\bid5\{0}\{1}_{0}.xls",code,DateUtils.getYYYYMMDD_NoSlash(date));
            if (File.Exists(fileName))
                return fileName;
            return null;
        }
        protected static List<StockMinuteDataSlice> loadMinuteDataSliceFromFile(String fileName)
        {
            String sheetName="bid5";
            List<StockMinuteDataSlice> result = new List<StockMinuteDataSlice>();
            using (System.Data.DataTable dataTable = ExcelHelper.GetDataTableFromExcelFile(fileName, ref  sheetName))
            {
                if (dataTable != null)
                {
                    int sz = dataTable.Rows.Count;
                    for (int i = 0; i < sz; i++)
                    {
                        System.Data.DataRow row = dataTable.Rows[i];
                        var 單量 = row[5];
                        if (String.IsNullOrWhiteSpace(單量.ToString()))
                            continue;
                        StockMinuteDataSlice slice = new StockMinuteDataSlice();
                        var 成交量 = row[6];
                        var 成交價 = row[7];
                        var DDETime = row["DDETime"];

                        slice.成交量 = Convert.ToDouble(成交量);
                        slice.成交價 = Convert.ToDouble(成交價);
                        slice.單量 = Convert.ToInt32(單量);
                        slice.time = DateTime.Parse(DDETime.ToString());
                        result.Add(slice);
                    }
                }
            }


            return result;
        }
        public static StockDailyDetailSummary getSummary(String code, DateTime date)
        {
            String fileName=getDataFileName(code,date);
            if(fileName==null)
                return null;

            loadMinuteDataSliceFromFile(fileName);


            return null;
        }


    }
}
